package com.guo.pet_store.admin.dao;

import com.guo.pet_store.admin.pojo.PetType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Type;
import java.util.List;

public interface TypeRepository extends JpaRepository<PetType,Long> {
    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "update type set name = ?2 where id = ?1")
    void updateType(Long typeId,String typeName);

//    查询所有为父id的type
    @Transactional
    @Query(nativeQuery = true,value = "select * from type where parent = 1")
    List<PetType> parentType();
//
    @Transactional
    @Query(nativeQuery = true,value = "select * from type where parent_id = ?1")
    List<PetType> sonType(Long parentId);

    @Transactional
    @Query(nativeQuery = true,value = "select * from type where parent = 0")
    List<PetType> listSonType();






}
